package window;

import cn.hutool.core.date.DateTime;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.Objects;

/**
 * @Author: youdao.hww
 * @Date: 10/20/24
 * @Desc:
 */
public class DateTimeTest {

    public static final String DATE_FORMAT = "yyyy-MM-dd";

    public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";

    public static void main(String[] args) {


        // 定义日期格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");


        // 解析字符串为 LocalDateTime 对象
        LocalDateTime startDateTime = LocalDateTime.parse("2025-01-01 06:00:00", formatter);

        LocalDateTime endDateTime = LocalDateTime.parse("2025-01-09 10:18:30", formatter);

        // 计算两日期间的完整天数差异
        long daysBetween = ChronoUnit.DAYS.between(startDateTime, endDateTime);
        System.out.println("完整天数差异: " + daysBetween + " 天");




    }


    public static Date getDate(String date, String format) {
        SimpleDateFormat df = new SimpleDateFormat(format);
        try {
            return df.parse(date);
        } catch (ParseException e) {
        }
        return null;
    }



    public static String getDate(Date date, String format) {
        return parse(date, format);
    }

    public static String parse(Date date, String formatString) {
        return toString(date, formatString);
    }


    public static String toString(Date currentDate, String dateTimeFormat) {
        DateTime dateTime = new DateTime(currentDate);
        return dateTime.toString(dateTimeFormat);
    }
}
